from django.core.management.base import LabelCommand, CommandError
from connie2_django.connie2.models import ConnieRun
from connie2_django.connie2.connieformatter import formatForConnie

class Command(LabelCommand):
    help="Re-create the input file for a given run id (can specify more than one, but they will be concatenated)"
    label="run id"

    def handle_label(self, label, **options):
        try:
            runid = int(label)
        except:
            raise CommandError, 'Run id "%s" must be an integer' % label

        try:
            run = ConnieRun.objects.get(id=runid)
        except:
            raise CommandError, "Run %d doesn't exist." % runid

        return formatForConnie(run)
